/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.facilscrum.form.dailyscrum;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import org.facilscrum.beans.Proyectos;
import org.facilscrum.beans.Scrumdiario;
import org.facilscrum.beans.Sprint;
import org.facilscrum.beans.Userstories;
import org.facilscrum.beans.Userstoriessprint;
import org.facilscrum.beans.Usuarios;
import org.facilscrum.controller.ProyectosController;
import org.facilscrum.controller.ScrumdiarioController;
import org.facilscrum.controller.SprintController;
import org.facilscrum.controller.UserstoriessprintController;
import org.facilscrum.controller.UsuariosController;
import org.facilscrum.generales.Mensajeria;
import org.facilscrum.sesion.MySesion;
import org.javscaz.javscaztools.tablas.CustomEditor;
import org.javscaz.javscaztools.tablas.CustomRenderer;
import org.javscaz.javscaztools.utilidades.Utilidades;

/**
 *
 * @author avbravo
 */
public class DailyScrumForm extends javax.swing.JInternalFrame {

    Proyectos proyectos = new Proyectos();
    ProyectosController proyectosController = new ProyectosController();
    Sprint sprint = new Sprint();
    SprintController sprintController = new SprintController();
    Scrumdiario scrumdiario = new Scrumdiario();
    ScrumdiarioController scrumdiarioController = new ScrumdiarioController();
    Userstoriessprint userstoriessprint = new Userstoriessprint();
    UserstoriessprintController userstoriessprintController = new UserstoriessprintController();
    UsuariosController usuariosController = new UsuariosController();
    Usuarios usuarios = new Usuarios();
    List<Usuarios> listUsuarios = new ArrayList<>();
    DefaultTableModel modelo;
    Integer idscrumdiario;
    Integer filaSeleccionada;

    /**
     * Creates new form DailyScrumForm
     */
    public DailyScrumForm() {
        initComponents();
        if (!MySesion.getSeleccionoProyectoTrabajo()) {
            Mensajeria.MensajeWarning("Debe indicar el proyecto de trabajo");
        } else {
            proyectos = MySesion.getProyectos();
            jTextFieldProyecto.setText(proyectos.getProyecto());
            jButtonGuardar.setEnabled(true);
            cargarComboSprint();

            java.util.Calendar ca = java.util.Calendar.getInstance();
            java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());
            jXDatePickerFecha.setDate(mydate);
            jXDatePickerFecha.setFormats(new SimpleDateFormat("dd/MM/yyyy"));
        }
        modelo = (DefaultTableModel) jTable1.getModel();
        TableColumn ayer = jTable1.getColumnModel().getColumn(2);
        ayer.setCellRenderer(new CustomRenderer());
        ayer.setCellEditor(new CustomEditor());

        TableColumn inconvenientes = jTable1.getColumnModel().getColumn(3);
        inconvenientes.setCellRenderer(new CustomRenderer());
        inconvenientes.setCellEditor(new CustomEditor());

        TableColumn hoy = jTable1.getColumnModel().getColumn(4);
        hoy.setCellRenderer(new CustomRenderer());
        hoy.setCellEditor(new CustomEditor());
        jTable1.setRowHeight(85);
        //search();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButtonEliminar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaAyer = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        jComboBoxSprint = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextAreaInconvenientes = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextAreaHoy = new javax.swing.JTextArea();
        jTextFieldProyecto = new javax.swing.JTextField();
        jButtonGuardar = new javax.swing.JButton();
        jXDatePickerFecha = new org.jdesktop.swingx.JXDatePicker();
        jLabel7 = new javax.swing.JLabel();
        jComboBoxUsuarios = new javax.swing.JComboBox();
        jButtonRegresar = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jFormattedTextFieldFechaInicio = new javax.swing.JFormattedTextField();
        jFormattedTextFieldFechaTerminacion = new javax.swing.JFormattedTextField();
        jButtonEditar = new javax.swing.JButton();
        jButtonNuevo = new javax.swing.JButton();

        setClosable(true);
        setTitle("Daily Scrum");

        jSplitPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jSplitPane1.setAutoscrolls(true);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Id", "Fecha", "Ayer", "Inconvenientes", "Hoy"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, true, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(60);

        jButtonEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/facilscrum/gif/deletetrash.png"))); // NOI18N
        jButtonEliminar.setToolTipText("Eliminar");
        jButtonEliminar.setEnabled(false);
        jButtonEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/facilscrum/gif/x16/search.png"))); // NOI18N
        jButton2.setToolTipText("Buscar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jButtonEliminar)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonEliminar)
                .addContainerGap(97, Short.MAX_VALUE))
        );

        jSplitPane1.setRightComponent(jPanel2);

        jLabel1.setText("Proyecto");

        jLabel2.setText("Fecha");

        jLabel3.setText("Quer hiciste ayer");

        jTextAreaAyer.setColumns(20);
        jTextAreaAyer.setRows(5);
        jScrollPane1.setViewportView(jTextAreaAyer);

        jLabel4.setText("Sprint");

        jComboBoxSprint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxSprintActionPerformed(evt);
            }
        });

        jLabel5.setText("Inconvenientes");

        jTextAreaInconvenientes.setColumns(20);
        jTextAreaInconvenientes.setRows(5);
        jScrollPane2.setViewportView(jTextAreaInconvenientes);

        jLabel6.setText("Que vas a hacer hoy");

        jTextAreaHoy.setColumns(20);
        jTextAreaHoy.setRows(5);
        jScrollPane3.setViewportView(jTextAreaHoy);

        jTextFieldProyecto.setEnabled(false);
        jTextFieldProyecto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldProyectoActionPerformed(evt);
            }
        });

        jButtonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/facilscrum/gif/Save.png"))); // NOI18N
        jButtonGuardar.setEnabled(false);
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        jLabel7.setText("Usuarios");

        jComboBoxUsuarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxUsuariosActionPerformed(evt);
            }
        });

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/facilscrum/gif/return.png"))); // NOI18N
        jButtonRegresar.setToolTipText("Regresar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jLabel8.setText("Inicio");

        jLabel9.setText("Terminacion");

        jFormattedTextFieldFechaInicio.setEnabled(false);

        jFormattedTextFieldFechaTerminacion.setEnabled(false);

        jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/facilscrum/gif/edit.png"))); // NOI18N
        jButtonEditar.setToolTipText("Editar");
        jButtonEditar.setEnabled(false);
        jButtonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditarActionPerformed(evt);
            }
        });

        jButtonNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/facilscrum/gif/new.png"))); // NOI18N
        jButtonNuevo.setToolTipText("Nuevo");
        jButtonNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNuevoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(73, 73, 73))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel1))
                                .addGap(86, 86, 86)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldProyecto, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
                                    .addComponent(jComboBoxSprint, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel8))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jFormattedTextFieldFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel9)
                                        .addGap(4, 4, 4)
                                        .addComponent(jFormattedTextFieldFechaTerminacion, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jComboBoxUsuarios, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jXDatePickerFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(52, 52, 52)
                                        .addComponent(jButtonNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addContainerGap(24, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldProyecto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jComboBoxSprint, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jFormattedTextFieldFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFormattedTextFieldFechaTerminacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jComboBoxUsuarios, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jXDatePickerFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButtonNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(75, 75, 75)
                        .addComponent(jLabel5)
                        .addGap(89, 89, 89)
                        .addComponent(jLabel6)
                        .addGap(0, 59, Short.MAX_VALUE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButtonGuardar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonRegresar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonEditar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(40, 40, 40))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jSplitPane1.setLeftComponent(jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jSplitPane1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 601, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldProyectoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldProyectoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldProyectoActionPerformed

    private void jComboBoxSprintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxSprintActionPerformed
        try {
            modelo = Utilidades.limpiarModelo(modelo);
            limpiar();
            int j = jComboBoxSprint.getSelectedIndex();
            if (j != -1) {
                sprint = sprintController.getSprintlist().get(j);
                jFormattedTextFieldFechaInicio.setText(Utilidades.formatearFecha(sprint.getFechainicio()));
                jFormattedTextFieldFechaTerminacion.setText(Utilidades.formatearFecha(sprint.getFechaterminacion()));
                cargarComboUsuarios();
            } else {
                Mensajeria.Mensaje("No se ha seleccionado ningun sprint");

            }
            jButtonEliminar.setEnabled(false);
            jButtonGuardar.setEnabled(false);
            jButtonEditar.setEnabled(false);

        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "combo()");
        }
    }//GEN-LAST:event_jComboBoxSprintActionPerformed

    private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed
        save(true);
    }//GEN-LAST:event_jButtonGuardarActionPerformed

    private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed
        dispose();
    }//GEN-LAST:event_jButtonRegresarActionPerformed

    private void jComboBoxUsuariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxUsuariosActionPerformed
        search();
    }//GEN-LAST:event_jComboBoxUsuariosActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        filaSeleccionada = jTable1.getSelectedRow();
        idscrumdiario = Integer.parseInt(modelo.getValueAt(filaSeleccionada, 0).toString());
        scrumdiario.setIdscrumdiario(idscrumdiario);
        Scrumdiario s = scrumdiarioController.findByPrimaryKey(scrumdiario);
        if (s == null) {
            Mensajeria.MensajeWarning("No se encuentra el scrumdiario con ese idscrum");
            return;
        } else {
            scrumdiario = s;
            jTextAreaAyer.setText(scrumdiario.getAyer());
            jTextAreaInconvenientes.setText(scrumdiario.getInconvenientes());
            jTextAreaHoy.setText(scrumdiario.getHoy());
            jXDatePickerFecha.setDate(scrumdiario.getFecha());
            jXDatePickerFecha.setFormats(new SimpleDateFormat("dd/MM/yyyy"));
        }
        jButtonEliminar.setEnabled(true);
        jButtonEditar.setEnabled(true);
        jButtonGuardar.setEnabled(false);
    }//GEN-LAST:event_jTable1MouseClicked

    private void jButtonEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEliminarActionPerformed
        try {
            if (idscrumdiario < 1) {
                Mensajeria.MensajeWarning("Seleccione un scrum diario de la lista");
                jButtonEliminar.setEnabled(false);
                jButtonEditar.setEnabled(false);
                return;
            }
            String respuesta = Mensajeria.PreguntaSiNo("Desea eliminar el scrum diario de la fecha\n" + modelo.getValueAt(filaSeleccionada, 0).toString(), "Eliminar?");
            if (respuesta.equals("si")) {
                String sql = "idscrumdiario='" + idscrumdiario + "'";
                if (scrumdiarioController.delete(sql)) {
                    Mensajeria.Mensaje("Eliminado exitosamente");
                    jButtonEliminar.setEnabled(false);
                    jButtonEditar.setEnabled(false);
                    jButtonGuardar.setEnabled(false);
                    cargarTablaDailyScrum();
                    limpiar();
                } else {
                    Mensajeria.MensajeWarning("No se pudo eliminar " + scrumdiarioController.getMensaje());
                }
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "Eliminar()");
        }
    }//GEN-LAST:event_jButtonEliminarActionPerformed

    private void jButtonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEditarActionPerformed
        save(false);
    }//GEN-LAST:event_jButtonEditarActionPerformed

    private void jButtonNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNuevoActionPerformed
        limpiar();
        jButtonGuardar.setEnabled(true);
        jButtonEditar.setEnabled(false);
        jButtonEliminar.setEnabled(false);
    }//GEN-LAST:event_jButtonNuevoActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        search();
    }//GEN-LAST:event_jButton2ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButtonEditar;
    private javax.swing.JButton jButtonEliminar;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JButton jButtonNuevo;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JComboBox jComboBoxSprint;
    private javax.swing.JComboBox jComboBoxUsuarios;
    private javax.swing.JFormattedTextField jFormattedTextFieldFechaInicio;
    private javax.swing.JFormattedTextField jFormattedTextFieldFechaTerminacion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextAreaAyer;
    private javax.swing.JTextArea jTextAreaHoy;
    private javax.swing.JTextArea jTextAreaInconvenientes;
    private javax.swing.JTextField jTextFieldProyecto;
    private org.jdesktop.swingx.JXDatePicker jXDatePickerFecha;
    // End of variables declaration//GEN-END:variables

    private void search() {
        try {
            if (listUsuarios.isEmpty()) {
                return;
            } else {
            }
            modelo = Utilidades.limpiarModelo(modelo);
            jButtonEliminar.setEnabled(false);
            limpiar();
            int k = jComboBoxUsuarios.getSelectedIndex();
            if (k != -1) {

                usuarios = listUsuarios.get(k);
                cargarTablaDailyScrum();
                jButtonGuardar.setEnabled(true);
                jButtonEditar.setEnabled(false);

            } else {
                return;
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "search() ");

        }
    }

    private Boolean cargarComboSprint() {
        try {

            jComboBoxSprint.removeAllItems();

            String where = "idproyecto='" + proyectos.getIdproyecto() + "' and abierto='si' ";

            if (sprintController.query(where)) {
                for (Sprint s : sprintController.getSprintlist()) {
                    jComboBoxSprint.addItem(s.getIdsprint() + " - " + s.getNombre());
                }
                return true;
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "cargarComboSprint() ");

        }
        return false;
    }

    private Boolean cargarComboUsuarios() {
        try {
            listUsuarios.removeAll(listUsuarios);
            jComboBoxUsuarios.removeAllItems();
            String sql = "idsprint='" + sprint.getIdsprint() + "'";
            Boolean encontrado = false;

            if (userstoriessprintController.query(sql)) {
                for (Userstoriessprint u : userstoriessprintController.getUserstoriessprintlist()) {

                    encontrado = false;

                    for (Usuarios us : listUsuarios) {

                        if (us.getCedula().equals(u.getUserstories().getUsuarios().getCedula())) {
                            encontrado = true;
                        }

                    }
                    if (!encontrado) {
                        Usuarios usuarios1 = new Usuarios();
                        usuarios1 = u.getUserstories().getUsuarios();
                        jComboBoxUsuarios.addItem(u.getUserstories().getUsuarios().getNombre() + " " + u.getUserstories().getUsuarios().getCedula());
                        listUsuarios.add(usuarios1);
                    }

                }
                return true;
            } else {
                Mensajeria.Mensaje("Debe crear primero los usuarios ");
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "cargarComboUsuarios() ");

        }
        return false;
    }

    private void cargarTablaDailyScrum() {
        try {
            modelo = Utilidades.limpiarModelo(modelo);
            String where = "idsprint='" + sprint.getIdsprint() + "' and username='" + usuarios.getUsername() + "'";
            if (scrumdiarioController.query(where)) {
                for (Scrumdiario s : scrumdiarioController.getScrumdiariolist()) {
                    Object[] filas = new Object[5]; // Hay tres columnas en la tabla       
                    filas[0] = s.getIdscrumdiario();
                    filas[1] = MySesion.formatearFechaToString(s.getFecha());
                    filas[2] = s.getAyer();
                    filas[3] = s.getInconvenientes();
                    filas[4] = s.getHoy();
                    modelo.addRow(filas);
                }
            }

        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "cargarTablaDailyScrum()");
        }
    }

    private void limpiar() {
        try {
            jTextAreaAyer.setText("");
            jTextAreaHoy.setText("");
            jTextAreaInconvenientes.setText("");
        } catch (Exception ex) {
        }
    }

    private void save(Boolean nuevo) {
        try {

            if (jTextAreaAyer.getText() == null || jTextAreaAyer.getText().equals("")) {
                Mensajeria.Mensaje("Debe indicar lo que hizo ayer");
                jTextAreaAyer.requestFocus();
                return;
            }

            if (jTextAreaInconvenientes.getText() == null || jTextAreaInconvenientes.getText().equals("")) {
                Mensajeria.Mensaje("Debe indicar los inconvenientes");
                jTextAreaInconvenientes.requestFocus();
                return;
            }
            if (jTextAreaHoy.getText() == null || jTextAreaHoy.getText().equals("")) {
                Mensajeria.Mensaje("Debe indicar lo que hara hoy");
                jTextAreaHoy.requestFocus();
                return;
            }
            int k = jComboBoxUsuarios.getSelectedIndex();
            if (k != -1) {
                usuarios = listUsuarios.get(k);

            } else {
                Mensajeria.Mensaje("No se ha seleccionado ningun usuario");
                return;
            }
            java.util.Date Fecha = jXDatePickerFecha.getDate();
            java.sql.Date fecha = new java.sql.Date(Fecha.getTime());
            if (fecha == null) {
                Mensajeria.MensajeWarning("Seleccione la fecha inicio");
                jXDatePickerFecha.requestFocus();
                return;
            }
            if (fecha.after(sprint.getFechaterminacion())) {
                Mensajeria.MensajeWarning("La fecha  no debe ser mayor  \nque la fecha de terminacion del sprint");
                return;
            }
            if (fecha.before(sprint.getFechainicio())) {
                Mensajeria.MensajeWarning("La fecha  no debe ser menor  \nque la fecha de inicio del sprint");
                return;
            }
            if (nuevo) {
                String sql = "idsprint='" + sprint.getIdsprint() + "'  and username='" + usuarios.getUsername() + "' and fecha='" + fecha + "'";
                if (scrumdiarioController.query(sql)) {
                    Mensajeria.MensajeWarning("Existe un registro de scrum diario  en esta fecha");
                    return;
                }
            }

            if (!nuevo) {
                scrumdiario.setIdscrumdiario(idscrumdiario);
                Scrumdiario s = scrumdiarioController.findByPrimaryKey(scrumdiario);
                if (s == null) {
                    Mensajeria.MensajeWarning("No se encuentra el scrumdiario con ese idscrum");
                    return;
                } else {
                    scrumdiario = s;
                }
            }
            scrumdiario.setAyer(jTextAreaAyer.getText());
            scrumdiario.setHoy(jTextAreaHoy.getText());
            scrumdiario.setInconvenientes(jTextAreaInconvenientes.getText());
            scrumdiario.setFecha(fecha);
            scrumdiario.setIdsprint(sprint.getIdsprint());
            scrumdiario.setUsername(usuarios.getUsername());
            if (!nuevo) {
                if (scrumdiarioController.update(scrumdiario)) {
                    Mensajeria.Mensaje("Editado exitosamente");
                    limpiar();
                    cargarTablaDailyScrum();
                } else {
                    Mensajeria.MensajeWarning("No se ha actualizado el registro " + scrumdiarioController.getMensaje());
                }
            } else {
                if (scrumdiarioController.insert(scrumdiario)) {
                    Mensajeria.Mensaje("Guardado exitosamente");
                    limpiar();
                    cargarTablaDailyScrum();
                } else {
                    Mensajeria.MensajeWarning("No se ha guardado el registro " + scrumdiarioController.getMensaje());
                }
            }
            jButtonGuardar.setEnabled(false);
            jButtonEliminar.setEnabled(false);
            jButtonEditar.setEnabled(false);

        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "guiToData");
        }

    }
}
